package com.edgar.plugin.utils;

import android.content.Context;
import android.util.Log;

import com.edgar.plugin.SystemClassHolder;

import dalvik.system.BaseDexClassLoader;
import dalvik.system.DexClassLoader;

/**
 * Created by Edgar on 2018/2/11.
 */
public final class DexUtils {

    private static final String TAG = "DexUtils";
    private DexUtils(){}

    public static void installDex(Context context, DexClassLoader pluginClassLoader){
        Object dexElements1 = getDexElements(getPathList(context.getClassLoader()));
        Object dexElements2 = getDexElements(getPathList(pluginClassLoader));
        Log.d(TAG,"dexElements1:"+dexElements1);
    }

    private static Object getDexElements(Object dexPath){
        return FieldUtils.readField(dexPath,"dexElements");
    }

    private static Object getPathList(ClassLoader classLoader){
        return FieldUtils.readField(SystemClassHolder.baseDexClassLoaderClass(),classLoader,"pathList");
    }
}